package com.simple.gateway.center.basedata.repository;

import com.simple.gateway.center.basedata.common.SimpleGatewayConstants;
import com.simple.gateway.center.basedata.mapper.HttpStatementMapper;
import com.simple.gateway.center.basedata.po.HttpStatement;
import com.simple.gateway.center.domian.api.bo.ApiData;
import com.simple.gateway.center.domian.api.repository.IApiRepository;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 项目: simple-gateway
 * <p>
 * 功能描述:
 *
 * @author: WuChengXing
 * @create: 2023-08-06 18:42
 **/
@Component
public class ApiRepository implements IApiRepository {

    @Resource
    private HttpStatementMapper httpStatementMapper;

    @Override
    public List<ApiData> queryHttpStatementList() {
        HttpStatement param = new HttpStatement();
        param.setIsDeleted(SimpleGatewayConstants.NOT_DELETED);
        List<HttpStatement> httpStatements = httpStatementMapper.listHttpStatement(param);
        List<ApiData> apiDataList = new ArrayList<>(httpStatements.size());
        for (HttpStatement httpStatement : httpStatements) {
            ApiData apiData = new ApiData();
            apiData.setApplication(httpStatement.getApplication());
            apiData.setInterfaceName(httpStatement.getInterfaceName());
            apiData.setMethodName(httpStatement.getMethodName());
            apiData.setParameterType(httpStatement.getParameterType());
            apiData.setUri(httpStatement.getUri());
            apiData.setHttpCommandType(httpStatement.getHttpCommandType());
            apiData.setAuth(httpStatement.getAuth());
            apiDataList.add(apiData);
        }
        return apiDataList;
    }
}
